package com.fengxu.springcloud.service.impl;

import com.fengxu.springcloud.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
*@Description IMessageProvider接口实现类
*@Author 风珝
*@Date 2021/1/18 21:27
*@Version 1.0.0
*/
// 开启绑定器 和rabbitmq进行绑定
// 消息生产者使用Source,消费者使用Sink
@EnableBinding(Source.class)
public class MessageProvider implements IMessageProvider {

    @Qualifier("output")
    @Autowired
    private MessageChannel outputMessage; // 消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString().replace("-","");
        outputMessage.send(MessageBuilder.withPayload(serial).build());
        System.out.println("******* serial = " + serial + " ********");
        return serial;
    }
}
